package com.everflourish.yeah100.act.base;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.everflourish.yeah100.act.markingsystem.MarkingMenuActivity;
import com.everflourish.yeah100.ui.dialog.LoadDialog;

/**
 * fragment基类
 *
 * @author pf
 * @date 2015-4-17
 */
public class BaseFragment extends Fragment {

    public static Context mContext;
    public RequestQueue mQueue;
    protected boolean isVisible;
    public LoadDialog mLoadDialog;
    public MarkingMenuActivity mMarkingMenuActivity;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mContext = getActivity();
        if(getActivity() instanceof MarkingMenuActivity){
            mMarkingMenuActivity = (MarkingMenuActivity) getActivity();
        }
        mQueue = Volley.newRequestQueue(mContext);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mQueue != null) {
            mQueue.stop();
        }
    }

    /**
     * 在这里实现Fragment数据的缓加载
     *
     * @param isVisibleToUser
     */
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (getUserVisibleHint()) {
            isVisible = true;
            onVisible();
        } else {
            isVisible = false;
            onInvisible();
        }
    }

    protected void onVisible() {
        lazyLoad();
    }

    protected void lazyLoad() {
    }

    protected void onInvisible() {


    }
}
